
template <class T>
class ATL_NO_VTABLE CBaseNodeItem : public CSnapInItemImpl<T>
{
public:
	static const GUID* m_NODETYPE;
	static const OLECHAR* m_SZNODETYPE;
	static const OLECHAR* m_SZDISPLAY_NAME;
	static const CLSID* m_SNAPIN_CLASSID;

	CBaseNodeItem()
	{
		m_bstrDisplayName = m_SZDISPLAY_NAME;
	}

	virtual ~CBaseNodeItem()
	{
	}    

   // CSnapInItemImpl
   STDMETHOD(GetScopePaneInfo)(SCOPEDATAITEM *pScopeDataItem)
   {
		if (pScopeDataItem->mask & SDI_STR)
			pScopeDataItem->displayname = m_bstrDisplayName;
		if (pScopeDataItem->mask & SDI_IMAGE)
			pScopeDataItem->nImage = m_scopeDataItem.nImage;
		if (pScopeDataItem->mask & SDI_OPENIMAGE)
			pScopeDataItem->nOpenImage = m_scopeDataItem.nOpenImage;
		if (pScopeDataItem->mask & SDI_PARAM)
			pScopeDataItem->lParam = m_scopeDataItem.lParam;
		if (pScopeDataItem->mask & SDI_STATE )
			pScopeDataItem->nState = m_scopeDataItem.nState;

		return S_OK;
   }

   // CSnapInItemImpl
   STDMETHOD(GetResultPaneInfo)(RESULTDATAITEM *pResultDataItem)
   {
	if (pResultDataItem->bScopeItem)
	{
		if (pResultDataItem->mask & RDI_STR)
			pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
		if (pResultDataItem->mask & RDI_IMAGE)
			pResultDataItem->nImage = m_scopeDataItem.nImage;
		if (pResultDataItem->mask & RDI_PARAM)
			pResultDataItem->lParam = m_scopeDataItem.lParam;

		return S_OK;
	}

	if (pResultDataItem->mask & RDI_STR)
		pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
	if (pResultDataItem->mask & RDI_IMAGE)
		pResultDataItem->nImage = m_resultDataItem.nImage;
	if (pResultDataItem->mask & RDI_PARAM)
		pResultDataItem->lParam = m_resultDataItem.lParam;
	if (pResultDataItem->mask & RDI_INDEX)
		pResultDataItem->nIndex = m_resultDataItem.nIndex;

	return S_OK;
  }

   virtual LPOLESTR GetResultPaneColInfo(int nCol)
   {
		return m_bstrDisplayName;
   }

   // CSnapInItemImpl
   STDMETHOD(Notify)(MMC_NOTIFY_TYPE event, long arg, long param,
      IComponentData* pComponentData, IComponent* pComponent,
      DATA_OBJECT_TYPES type)
   {
		// Add code to handle the different notifications.
		// Handle MMCN_SHOW and MMCN_EXPAND to enumerate children items.
		// In response to MMCN_SHOW you have to enumerate both the scope
		// and result pane items.
		// For MMCN_EXPAND you only need to enumerate the scope items
		// Use IConsoleNameSpace::InsertItem to insert scope pane items
		// Use IResultData::InsertItem to insert result pane item.
		HRESULT hr = E_NOTIMPL;

		
		_ASSERTE(pComponentData != NULL || pComponent != NULL);

		CComPtr<IConsole> spConsole;
		CComQIPtr<IHeaderCtrl, &IID_IHeaderCtrl> spHeader;
		if (pComponentData != NULL)
			spConsole = ((CSnapIn*)pComponentData)->m_spConsole;
		else
		{
			spConsole = ((CUserComponent*)pComponent)->m_spConsole;
			spHeader = spConsole;
		}

		switch (event)
		{
		case MMCN_CONTEXTHELP:
			hr = OnShowContextHelp(((CUserComponent*)pComponent)->m_ipDisplayHelp);
			break;
		case MMCN_SHOW:
			{
				hr=OnShow(spConsole, arg);				
				break;
			}
		case MMCN_EXPAND:
			{
				hr = OnExpand(arg, spConsole, param);
				break;
			}
		case MMCN_ADD_IMAGES:
			{
	         hr = OnAddImages((IImageList*) arg);
			 break;
			}
		case MMCN_DBLCLICK:
			{
			 hr = spConsole->SelectScopeItem(m_scopeDataItem.ID);
			break;
			}
		case MMCN_SELECT:
			{
			 hr = OnSelect(spConsole, pComponent);
			break;
			}
		case MMCN_RENAME:
			{
			 hr = OnRename(spConsole, (LPOLESTR)param);

			break;
			}
		}
		return hr;
   }

   HRESULT OnAddImages(IImageList* pImageList)
   {
	   return CSnapIn::LoadImages(pImageList);
   }
   	// CSnapInItemImpl
	STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,long handle, 
								   IUnknown* pUnk,DATA_OBJECT_TYPES type)
	{
		return S_FALSE;
	}
	// CSnapInItemImpl
	STDMETHOD(QueryPagesFor)(DATA_OBJECT_TYPES type)
	{
		return S_FALSE;
	}

   // virtual functions called by Notify
   //MMCN_CONTEXTHELP
	virtual HRESULT OnShowContextHelp(IDisplayHelp *pDisplayHelp) 
	{ return S_FALSE; }
	//MMCN_EXAPND
	virtual HRESULT OnExpand(BOOL bExpand, IConsole *pConsole, HSCOPEITEM parent) 
	{ return S_FALSE; }
	//MMCN_SHOW
	virtual HRESULT OnShow(IConsole *pConsole, BOOL bShow)
	{ return S_FALSE; }
	//MMCN_SELECT
	virtual HRESULT OnSelect(IConsole *spConsole, IComponent* pComponent )
	{ return S_FALSE; }
	//MMCN_RENAME
	virtual HRESULT OnRename(IConsole* pConsole, LPOLESTR param)
	{ return S_FALSE; }
};